package org.mnswf.services {
	
	import com.dannypatterson.remoting.FaultEvent;
	import com.dannypatterson.remoting.ResultEvent;
	import com.dannypatterson.remoting.ServiceProxy;
	import flash.events.EventDispatcher;
	import org.mnswf.model.Member;
	import com.dannypatterson.config.Settings;
	import mx.managers.CursorManager;
	
	public class GetPendingMembersService extends EventDispatcher implements IService {
	
		private var service:ServiceProxy;
		
		public function GetPendingMembersService() {
			service = new ServiceProxy(Settings.getInstance().remotingGateway, Settings.getInstance().memberService);
			service.addEventListener(ResultEvent.RESULT, onComplete, false, 0, true);
			service.addEventListener(FaultEvent.FAULT, onFault, false, 0, true);
		}
		
		private function onComplete(event:ResultEvent):void {
			CursorManager.removeBusyCursor();
			var members:Array = new Array();
			for(var i:Number = 0; i < event.result.length; i++) {
				var member:Member = new Member();
				member.parseTransferObject(event.result[i]);
				members.push(member);
			}
			dispatchEvent(new ResultEvent(ResultEvent.RESULT, event.bubbles, event.cancelable, members));
		}
		
		private function onFault(event:FaultEvent):void {
			CursorManager.removeBusyCursor();
			dispatchEvent(new FaultEvent(FaultEvent.FAULT, event.bubbles, event.cancelable, event.fault));
		}
		
		public function execute():void {
			CursorManager.setBusyCursor();
			service.getPendingMembers();
		}
		
	}
}